﻿CREATE VIEW [dbo].[ASMS_V_PackageInstanceItemChangedRecord]
	AS 
SELECT PIICR.*,
	P.Name as PackageName,
	[PI].Name as PackageItemName,
	B.Name as BusinessName,
	S.Name as StationName,
	C.Name as CustomerName,
	C.Telephone  as CustomerTelephone,
	PInst.CustomerId as CustomerId
FROM ASMS_PackageInstanceItemChangedRecord as PIICR
	left join ASMS_PackageInstance as PInst on PInst.Id = PIICR.PackageInstanceId
	left join ASMS_PackageInstanceItem as PII on PII.Id = PIICR.PackageInstanceItemId
	left join ASMS_Package as P on P.Id = PInst.PackageId
	left join ASMS_PackageItem as [PI] on [PI].Id = PII.PackageItemId
	left join ASMS_Business as B on B.Id = PIICR.BusinessId
	left join ASMS_Station as S on S.Id = PIICR.StationId
	left join ASMS_Customer as C on C.Id = PInst.CustomerId